﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using BCL.Repository;

public partial class Admin_ToDayList : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            to = 0;
            from = 20;
        }

        Bind();
    }
    private int to { get; set; }
    private int from { get; set; }
    void Bind()
    {
        NewsRepository newRepo = new NewsRepository();
        DateTime? currentDate = null;
        if (!string.IsNullOrEmpty(txtDate.Text))
            currentDate = Convert.ToDateTime(txtDate.Text);

        int fromRecordNumber = CustomGrid1.PageIndex * CustomGrid1.PageSize + 1;
        int toRecordNumber = fromRecordNumber + CustomGrid1.PageSize - 1;

        var result = newRepo.Search(currentDate, 11, fromRecordNumber, toRecordNumber);

        if (result != null && result.Count != 0)
            CustomGrid1.VirtualItemCount = result[0].TotalCount;
        CustomGrid1.DataSource = result;
        CustomGrid1.DataBind();
    }
    protected void CustomGrid1_PageIndexChanged(object sender, EventArgs e)
    {
        Bind();
    }


    protected void CustomGrid1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        CustomGrid1.PageIndex = e.NewPageIndex;
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        CustomGrid1.PageIndex = 0;
        Bind();
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        CustomGrid1.PageIndex = 0;
        txtDate.Text = "";
        Bind();
    }
}